package com.demandbreakdown.xiyun.model.vo.user;

import com.demandbreakdown.xiyun.model.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 用户信息VO
 *
 * @author poxz
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "用户信息VO")
public class UserVO {
    @Schema(description = "用户ID", example = "123")
    private Long id;

    @Schema(description = "用户账号", example = "alice")
    private String userAccount;

    @Schema(description = "邮箱地址", example = "alice@example.com")
    private String email;

    @Schema(description = "用户昵称", example = "Alice")
    private String userName;

    @Schema(description = "用户头像", example = "https://oss/xxx.jpg")
    private String userAvatar;

    @Schema(description = "用户简介", example = "个人简介")
    private String userProfile;

    @Schema(description = "用户角色：user/admin", example = "user")
    private String userRole;

    @Schema(description = "用户状态：0-禁用，1-正常", example = "1")
    private Integer userStatus;

    @Schema(description = "创建时间", example = "2025-09-20T12:00:00Z")
    private LocalDateTime createTime;

    public static UserVO from(User user) {
        if (user == null) {
            return null;
        }
        return UserVO.builder()
                .id(user.getId())
                .userAccount(user.getUserAccount())
                .email(user.getEmail())
                .userName(user.getUserName())
                .userAvatar(user.getUserAvatar())
                .userProfile(user.getUserProfile())
                .userRole(user.getUserRole())
                .userStatus(user.getUserStatus())
                .createTime(user.getCreateTime())
                .build();
    }

    /**
     * 从User实体转换为UserVO
     *
     * @param user  用户对象
     * @param token 访问令牌
     * @return UserVO
     */
    public static UserVO from(User user, String token) {
        // 出于安全考虑，token信息不在UserVO中返回，由独立的登录接口返回
        return from(user);
    }
}
